<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${tableClass.shortClassName}EntityMapper">

    <resultMap id="BaseResultMap" type="${tableClass.fullClassName}Entity">
    <#if tableClass.pkFields??>
        <#list tableClass.pkFields as field>
        <id column="${field.columnName}" jdbcType="${field.jdbcType}" property="${field.fieldName}" />
        </#list>
    </#if>
    <#if tableClass.baseFields??>
        <#list tableClass.baseFields as field>
        <result column="${field.columnName}" jdbcType="${field.jdbcType}" property="${field.fieldName}" />
        </#list>
    </#if>
    </resultMap>

    <sql id="Base_Column_List" >
        <#list tableClass.allFields as field>${field.columnName}<#if field_has_next>,</#if></#list>
    </sql>

    <sql id="limit">
        <if test="start != null and limit !=null">
            ${r"limit #{start},#{limit}"}
        </if>
    </sql>

    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
        select <include refid="Base_Column_List" /> from ${tableClass.tableName}
        where
        <#list tableClass.pkFields as field>${field.columnName} = ${r"#{"}${field.fieldName},jdbcType=${field.jdbcType}}<#if field_has_next> and </#if></#list>
        and del_flag = 0
    </select>

    <select id="selectByParams" resultMap="BaseResultMap" parameterType="${tableClass.fullClassName}Entity" >
        select
        <include refid="Base_Column_List" />
        from ${tableClass.tableName}
        where
    <#list tableClass.baseFields as field>
        <#if field.columnName != "del_flag" && field.columnName != "del_flag" && field.columnName != "update_time" && field.columnName != "add_time" && field.columnName != "create_time" >
            <if test="${field.fieldName} != null" >
            ${field.columnName} = ${r"#{"}${field.fieldName},jdbcType=${field.jdbcType}}<#if field_has_next> and </#if>
            </if>
        </#if>
    </#list>
        del_flag = 0
        <include refid="limit" />
    </select>

    <select id="selectList" resultMap="BaseResultMap" parameterType="${tableClass.fullClassName}Entity" >
        select
        <include refid="Base_Column_List" />
        from ${tableClass.tableName}
        where
        <#list tableClass.baseFields as field>
            <#if field.columnName != "del_flag" && field.columnName != "del_flag" && field.columnName != "update_time" && field.columnName != "add_time" && field.columnName != "create_time" >
            <if test="${field.fieldName} != null" >
                ${field.columnName} = ${r"#{"}${field.fieldName},jdbcType=${field.jdbcType}}<#if field_has_next> and </#if>
            </if>
            </#if>
        </#list>
             del_flag = 0
        <include refid="limit" />
    </select>


    <insert id="insertSelective" parameterType="${tableClass.fullClassName}Entity" useGeneratedKeys="true" keyProperty="id" >
        insert into ${tableClass.tableName}
        <trim prefix="(" suffix=")" suffixOverrides="," >
        <#list tableClass.allFields as field>
            <if test="${field.fieldName} != null" >
            ${field.columnName},
            </if>
        </#list>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
        <#list tableClass.allFields as field>
            <if test="${field.fieldName} != null" >
            ${r"#{"}${field.fieldName},jdbcType=${field.jdbcType}},
            </if>
        </#list>
        </trim>
    </insert>

    <insert id="insert" parameterType="${tableClass.fullClassName}Entity" useGeneratedKeys="true" keyProperty="id">
        insert into ${tableClass.tableName}
        <trim prefix="(" suffix=")" suffixOverrides="," >
        <#list tableClass.allFields as field>
            ${field.columnName},
        </#list>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
        <#list tableClass.allFields as field>
            ${r"#{"}${field.fieldName},jdbcType=${field.jdbcType}},
        </#list>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective" parameterType="${tableClass.fullClassName}Entity">
        update ${tableClass.tableName}
        <set >
            <#list tableClass.baseFields as field>
            <if test="${field.fieldName} != null" >
            ${field.columnName} = ${r"#{"}${field.fieldName},jdbcType=${field.jdbcType}},
            </if>
            </#list>
        </set>
        where
        <#list tableClass.pkFields as field>${field.columnName} = ${r"#{"}${field.fieldName},jdbcType=${field.jdbcType}}<#if field_has_next> and </#if></#list> and del_flag = 0
    </update>

    <update id="updateByPrimaryKey" parameterType="${tableClass.fullClassName}Entity">
        update ${tableClass.tableName}
        <set >
            <#list tableClass.baseFields as field>
            ${field.columnName} = ${r"#{"}${field.fieldName},jdbcType=${field.jdbcType}},
            </#list>
        </set>
        where
        <trim prefix="" suffixOverrides="and|or" >
        <#list tableClass.pkFields as field>
                and ${field.columnName} = ${r"#{"}${field.fieldName},jdbcType=${field.jdbcType}}
        </#list>
        </trim>
        and del_flag = 0
    </update>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
        delete from ${tableClass.tableName}
        where
        <#list tableClass.pkFields as field>${field.columnName} = ${r"#{"}${field.fieldName},jdbcType=${field.jdbcType}}<#if field_has_next> and </#if></#list> and del_flag = 0
    </delete>
</mapper>